package cn.tedu.onlinestore.review.controller;

import cn.tedu.onlinestore.base.response.JsonResult;
import cn.tedu.onlinestore.review.pojo.dto.AddReviewParam;
import cn.tedu.onlinestore.review.pojo.vo.ReviewVO;
import cn.tedu.onlinestore.review.service.ReviewService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/v1/review/")
public class ReviewController {

    @Autowired
    private ReviewService reviewService;

    @PostMapping("add")
    public JsonResult addReview(AddReviewParam addReviewParam) {
        log.debug("新增评论列表：{}",addReviewParam);
        reviewService.addReview(addReviewParam);
        return JsonResult.ok();
    }

    @GetMapping("select/{id}")
    public JsonResult selectReviewById(@PathVariable Integer id) {
        log.debug("查询评论列表：{}",id);
        List<ReviewVO> list =  reviewService.selectReviewById(id);
        return JsonResult.ok(list);
    }

    @GetMapping("getAllReview")
    public JsonResult getAllReview(Integer page,Integer size) {
        log.debug("查询全部评论列表：{}",page);
        List<ReviewVO> list =  reviewService.getAllReview(page,size);
        return JsonResult.ok(list);
    }

    @PostMapping("delete")
    public JsonResult deleteReview(Integer id) {
        log.debug("删除评论列表：{}",id);
        reviewService.deleteReview(id);
        return JsonResult.ok();
    }
}
